package com.example.demo.controller;

import com.example.demo.model.Hero;
import com.example.demo.service.HeroService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Hae
 * @Date 2019/9/12 10:37
 * @Version 1.0
 */
@RestController
@RequestMapping("/hero")
public class HeroController {

    @Autowired
    private HeroService heroService;

    @GetMapping("/getAll")
    public List<Hero> getAll() {
        return heroService.getAllHeros();
    }

    @GetMapping("/getHeroByName")
    public List<Hero> getHeroByName(@RequestParam("name") String name) {
        return heroService.getHeroByName(name);
    }

    @GetMapping("/getHeroById")
    public Hero getHeroById(@RequestParam("id") int id) {
        return heroService.getHeroById(id);
    }

    @PostMapping("/addHero")
    public int addHero(@RequestBody Hero hero) {
        return heroService.addHero(hero);
    }

    @PostMapping("/updateHero")
    public int updateHero(@RequestBody Hero hero) {
        return heroService.updateHero(hero);
    }

    @GetMapping("/deleteHero")
    public int deleteHero(@RequestParam("id") int id) {
        return heroService.deleteHero(id);
    }
}
